<template>
  <div class="dialog-wrap" v-if="isShow">
    <div class="dialog-inner">
      <div class="dialog-content">
        <div class="title">
          <slot name="title">{{ dialogInfo.title }}</slot>
        </div>
        <div class="desc">
          <slot>
            <div v-html="$xss(dialogInfo.desc)"></div>
          </slot>
        </div>
        <div class="btns">
          <slot name="btns"
            ><Button round type="info" @click="confirm">确定</Button>
            <Button
              round
              type="default"
              @click="cancel"
              v-if="dialogInfo.type == 1"
              >取消</Button
            ></slot
          >
        </div>
      </div>
      <slot name="icon"><img :src="icon" alt="" class="dialog-icon" /></slot>
    </div>
  </div>
</template>
<script>
import { Button } from "vant";
export default {
  name: "dialogView",
  computed: {
    icon() {
      return "";
    },
    dialogInfo() {
      return this.$store.getters.dialogInfo;
    },
    dialogCtx() {
      return this.$store.state.dialog;
    },
    isShow: {
      get() {
        return this.$store.getters.dialogStatus;
      },
      set(value) {
        this.$store.commit("dialog/set_dialog_status", value);
      },
    },
  },
  components: { Button },
  mounted() {},
  methods: {
    confirm() {
      if (this.dialogInfo.autoConfirmClose) {
        this.isShow = false;
      }
      this.dialogCtx._promiseResolve &&
        this.dialogCtx._promiseResolve(() => (this.isShow = false));
    },
    cancel() {
      if (this.dialogInfo.autoCancelClose) {
        this.isShow = false;
      }
      this.dialogCtx._promiseReject &&
        this.dialogCtx._promiseReject(() => (this.isShow = false));
    },
  },
};
</script>
<style scoped lang="scss">
.dialog-wrap {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 99999;
}
.dialog-inner {
  width: 580px;
  min-height: 435px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, #e0f0ff 0%, #f5faff 21%, #ffffff 100%);
  border-radius: 20px;
  .dialog-content {
    position: relative;
    z-index: 2;
  }
  .title {
    font-weight: 500;
    font-size: 34px;
    line-height: 1;
    margin-top: 72px;
    padding: 0 56px;
    color: #181818;
    margin-bottom: 56px;
  }
  .desc {
    color: #666666;
    line-height: 1.8;
    border-bottom: 1px solid #eee;
    margin-bottom: 40px;
    padding: 0 56px;
    padding-bottom: 40px;
    min-height: 64px;
  }
}
.dialog-icon {
  position: absolute;
  width: 160px;
  pointer-events: none;
  right: 48px;
  top: 16px;
  z-index: 1;
}
.btns {
  text-align: center;
  margin-bottom: 60px;
  .van-button {
    width: 256px;
    height: 72px;
    font-size: 28px;
    & + .van-button {
      margin-left: 0.5em;
    }
  }
}
</style>
